public class Test {
//按顺序打印⼀个数字的每⼀位(例如1234打印出1234) 利用递归
    public static void print(int n){
        if(n==1){
            System.out.println(n);
        }else {
            print(n / 10);
            System.out.println(n % 10);
        }
    }

    public static void main(String[] args) {
       print(123456789);
    }
    //求斐波那契数列的第n项。(迭代实现)
    // 1 1 2 3 5 8 .....

    public static int fib(int n){
        if(n==1||n==2){
            return 1;
        }
        int flg1 = 1;
        int flg2 = 1;
        int flg3 = 0;
        for (int i = 3; i <=n; i++) {
            flg3 = flg1+flg2;
            flg1=flg2;
            flg2=flg3;
        }
        return flg3;
    }
    public static void main1(String[] args) {
        System.out.println(fib(1));
        System.out.println(fib(3));
        System.out.println(fib(4));
        System.out.println(fib(20));

    }
}
